
import socket
import time
import json
import threading
import struct
import time
import random
import base64

MaxBytes = 1024*1024


def main():
    with open('/home/vmuser/work/robot/pyServer/camWPaiImg', 'rb') as f:
        b = f.read()
        c = b
        with open('/home/vmuser/work/robot/pyServer/camWPaiImg64', 'wb') as wf:
            jj = {
                "cmd": "get_snapshot",
                "state_code": 200,
                "id": "123456",
                "imgformat": "jpg",
                "imgdata": "14ewrfswtergfhbfr=="
            }
            d = base64.b64encode(c).decode()
            jj["imgdata"] = d
            jj_str = json.dumps(jj)
            data_len = len(jj_str)
            vz_head = b'\x56\x5a\00\00'+struct.pack("!I", data_len)
            wf.write(vz_head)
            wf.write(jj_str.encode())


def test_decode():
    with open('/home/vmuser/work/robot/pyServer/camWPaiImg64', 'rb') as f:
        b = f.read()
        b = b[0x60+3:-2]
        b.decode('utf-8')
        bb = base64.b64decode(b)
        with open('/home/vmuser/work/robot/pyServer/camWPaiImg11.jpg', 'wb') as wf:
            lent = wf.write(bb)
            print(lent)


if __name__ == '__main__':
    # test_decode()
    # main()
    pass
